/*
 * @lc app=leetcode.cn id=367 lang=javascript
 *
 * [367] 有效的完全平方数
 */

// @lc code=start
/**
 * @param {number} num
 * @return {boolean}
 */
var isPerfectSquare = function (num) {
    let l = 1, r = num
    let mid = 1
    if(num==1)return true
    while (l <= r) {
        mid = parseInt((l + r) / 2)
        if (mid * mid == num) {
            return true
        }
        else if (mid * mid > num) {
            r = --mid
        } else {
            l = ++mid
        }
    }
    return false
};
// @lc code=end

var isPerfectSquare = function (num) {
    let i = 1
    while (i * i < num) {
        i++
    }
    return i * i == num
};//迭代